package com.wanmait.wanmarecruit.webController;

import com.wanmait.wanmarecruit.entity.User;
import com.wanmait.wanmarecruit.service.ApplyPositionService;
import com.wanmait.wanmarecruit.service.NoticeService;
import com.wanmait.wanmarecruit.service.PositionHistoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/web")
public class WebPersonalHomePageController {

    @Resource
    private PositionHistoryService positionHistoryService;
    @Resource
    private NoticeService noticeService;
    @Resource
    private ApplyPositionService applyPositionService;
    //去个人主页（求职者）（张佳炜）
    @RequestMapping("/personal/homepage/personalHomePage")
    public ModelAndView goPersonalHomePage(HttpServletRequest request)
    {
        ModelAndView modelAndView = new ModelAndView();
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        Integer userId = user.getId();
        modelAndView.addObject("positionHistorys",positionHistoryService.getPositionHistoryByUserId(userId));
        modelAndView.addObject("notices",noticeService.selectAllNoticeByUser(userId,1,10));
        modelAndView.addObject("numOfNotice",noticeService.getAllNoticeNotRead(userId));
        modelAndView.addObject("numOfApplication",applyPositionService.selectCountByUser(userId));
        modelAndView.setViewName("/web/personal/homepage/personalHomePage");
        return modelAndView;
    }
}
